<?
require_once("EndpointOption.php");
class Endpoint
{
	private $parts;
	private $options;
	private $cookies;

	private $method;

	public function Endpoint($method = "GET")
	{
		//Does php really not have an enum?
		$this->method = $method;
		$this->parts = array();
		$this->options = array();
	}
	public function AddPart($value, $format=null)
	{
		if ($value == null)
			return;
		//urlencode shouldn't be here, but for the time being, it's the safest way
		$valueText = is_array($value) ? implode(array_map("urlencode", $value), ",") : urlencode($value);
		if ($valueText[0] == ".") exit;
		$partText = $format ? sprintf($format, $valueText) : $valueText;
		$this->parts[] = $partText;
	}
	public function AddOption($name, $value, $format=null)
	{
		if ($value == null)
			return;
		$valueText = is_array($value) ? implode(array_map("urlencode", $value), ",") : urlencode($value);
		$optionText = $format ? sprintf($format, $valueText) : $valueText;
		$this->options[] = new EndpointOption($name, $optionText);
	}
	public function AddCookie($name, $value, $format=null)
	{
		//refactor me pls
		if ($value == null)
			return;
		$valueText = is_array($value) ? implode(array_map("urlencode", $value), ",") : urlencode($value);
		$optionText = $format ? sprintf($format, $valueText) : $valueText;
		$this->cookies[] = new EndpointOption($name, $optionText);
	}
	public function GetParts()
	{
		return $this->parts;
	}
	public function GetOptions()
	{
		return $this->options;
	}
	public function GetCookies()
	{
		return $this->cookies;
	}
	public function GetMethod()
	{
		return $this->method;
	}
}
?>
